<template>
	<view class="wrap">
		<g-header rtype="searchText" :customstyle="gHeaderStyle" @rightclick="onSearchTap">
			<template v-slot:title>
				<view class="search" @click.stop="onSearchTap">
					<icon type="search" size="16" color="#ccc"></icon>
					<input type="text" placeholder="请输入关键词搜索" placeholder-class="app_phc" disabled>
				</view> 
			</template>
		</g-header>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="onSkipTap('purchaseNote', index)">
				<!-- <view class="item-status" v-if="index == 0">进行中</view>
				<view class="item-status outOfDate" v-if="index == 1">已过期</view> -->
				<view class="item-img">
					<u-image width="350rpx" height="350rpx" :src="item.cover"></u-image>
				</view>
				<view class="item-title app_ellipsis2">{{item.productName}}</view>
				<view class="item-bottom">
					<view class="item-avatar">
						<u-avatar :src="item.avatar" size="40"></u-avatar>
					</view>
					<view class="item-phone">{{item.secretTel}}</view>
					<view class="item-date">{{item.createTimeStr}}</view>
				</view>
			</view>
			<!-- <view class="item">
				<view class="item-img">
					<u-image width="350rpx" height="350rpx" src="../../static/images/img-goods.jpg"></u-image>
				</view>
				<view class="item-title app_ellipsis2">斜纹西装料斜纹西</view>
				<view class="item-bottom">
					<view class="item-avatar">
						<u-avatar src="../../static/images/icon-home-user.png" size="40"></u-avatar>
					</view>
					<view class="item-phone">138****8888</view>
					<view class="item-date">2020-12-13</view>
				</view>
			</view>
			<view class="item">
				<view class="item-img">
					<u-image width="350rpx" height="350rpx" src="../../static/images/img-goods.jpg"></u-image>
				</view>
				<view class="item-title app_ellipsis2">斜纹西装料斜纹西装料斜纹西装料斜纹西装料斜纹西装料斜纹西装料</view>
				<view class="item-bottom">
					<view class="item-avatar">
						<u-avatar src="../../static/images/icon-home-user.png" size="40"></u-avatar>
					</view>
					<view class="item-phone">138****8888</view>
					<view class="item-date">2020-12-13</view>
				</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				gHeaderStyle: {
					position: 'fixed',
					left: 0,
					top: 0,
				},
				list: [],
				totalPage: 1,
				page: 1,
				size: 100,
				hasLoad: false,
				noMore: false,
			}
		},
		onLoad(options) {
			this.keyword = options.keyword || ''
			this.updatePage()
		},
		onReachBottom() {
			this.page++
			this.getList()
		},
		methods: {
			updatePage() {
				this.resetPage()
				this.getList()
			},
			resetPage() {
				this.list = []
				this.totalPage = 1
				this.page = 1
				this.size = 15
				this.hasLoad = false
				this.noMore = false
			},
			onSkipTap(type, index) {
				let urlObj = {
					purchaseNote: () => {
						uni.navigateTo({
							url: `/pages/takeOrder/purchaseNote?purchaseId=${this.list[index].purchaseId}`
						})
					}
				}
				this.$g_util.navigationTo(urlObj, type)
			},
			onSearchTap() {
				uni.navigateBack()
			},
			getList() {
				if (this.page > this.totalPage) return
				this.$g_api.purchaseSearch({
					searchValue: this.keyword,
					pageNum: this.page,
					pageSize: this.size
				}).then(({
					rows
				}) => {
					uni.stopPullDownRefresh()
					this.hasLoad = true
					if (rows?.length > 0) {
						rows = this.$g_util.concatRequestUrl(rows, 'cover')
						rows = this.$g_util.concatRequestUrl(rows, 'avatar')
						rows.forEach(item =>{
							item.createTimeStr = new Date(item.createTime).Format('yyyy-MM-dd')
							// item.secretTel = item.tel.slice(0, 3) + '****' + item.tel.slice(7, 11)
						})
						this.list = this.list.concat(rows)
					} else {
						this.noMore = true
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.wrap {
		padding-top: calc(var(--status-bar-height) + 98rpx);
	}

	.search {
		transform: translateX(-16rpx);
		width: 560rpx;
		height: 60rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		border-radius: 30rpx;
		background-color: #f2f2f2;

		input {
			flex: 1;
			margin-left: 20rpx;
		}
	}

	.list {
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		padding: 18rpx;
	}

	.item {
		position: relative;
		width: 350rpx;
		border-radius: 10rpx;
		padding-bottom: 70rpx;
		margin-bottom: 18rpx;
		overflow: hidden;
		background-color: #fff;
	}

	.item-status {
		position: absolute;
		left: 0;
		top: 0;
		width: 100rpx;
		height: 40rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 10rpx 0px 20rpx 0px;
		font-size: 22rpx;
		color: #fff;
		background-color: #FF4C4C;
		z-index: 99;

		&.outOfDate {
			background-color: #999;
		}
	}

	.item-img {}

	.item-title {
		margin: 16rpx 16rpx 4rpx;
	}

	.item-bottom {
		position: absolute;
		bottom: 18rpx;
		left: 0;
		display: flex;
		align-items: center;
	}

	.item-avatar {
		font-size: 0;
		margin-left: 16rpx;
		margin-right: 10rpx;
	}

	.item-phone {
		margin-right: 30rpx;
		font-size: 20rpx;
	}

	.item-date {
		color: #999;
		font-size: 20rpx;
	}
</style>
